/*
 * Copyright (c) 2023, 2024,yzc.cn All rights reserved.
 *
 */
package com.by.server.impl;

import com.by.common.bean.Result;
import com.by.common.exception.BusinessException;
import com.by.mapper.FinPaymentMapper;
import com.by.pojo.FinPayment;
import com.by.remote.ContractStatusClient;
import com.by.server.FinPaymentServer;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>Project: erp-cloud-api - FinPaymentServerImpl</p>
 * <p>Powered by yzc On 2024-01-19 16:45:22</p>
 * <p>描述：<p>
 *
 * @author yzc [yzc0415@126.com]
 * @version 1.0
 * @since 17
 */
@Service
public class FinPaymentServerImpl implements FinPaymentServer {

    @Autowired
    FinPaymentMapper finPaymentMapper;

    @Autowired
    ContractStatusClient contractStatusClient;

    @GlobalTransactional
    @Override
    public int save(FinPayment finPayment) {
        int rs = finPaymentMapper.insert(finPayment);
        if (rs == 0){
            throw new BusinessException("保存失败");
        }
        Result result = contractStatusClient.updateStatus(finPayment.getContractCode(), 1);
        if (result.getCode() == 0){
            throw new BusinessException("更新失败");
        }
        return rs;
    }
}
